/**
 * 
 */

$(document).ready(function () {
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition( 
			function (position) {
				var params = {
					lat: position.coords.latitude,
					long: position.coords.longitude
						
//						city: position.address.city,
//						country: position.address.country,
//						countryCode: position.address.countryCode,
//						region: position.address.region,
//						streetNumber: position.address.streetNumber,
//						street: position.address.street
	    		};
	    		
				$.get("/index/set-user-location/format/json", params, function (resp) {
					ga_trackEvent('Journey', 'permitGeolocation', 'true');
					if (!resp.error) {
						window.location.reload();
					} else {
						
					}
    			}, 'json');
			}, 
			function (error)
			{
                            //PEX-898 David.B asked to turn off all popup messages regarding position
				switch(error.code) 
				{
					case error.TIMEOUT:
						alert ('Timeout');
						break;
					case error.POSITION_UNAVAILABLE:
						//alert ('Position unavailable');
					//	activepopup('Position unavailable');
						break;
					case error.PERMISSION_DENIED:
                                                // I denied the site access to my location
                                                // and the alert keeps popping up everytime
                                                // I refresh the page. I don't think we want that -marco
						//alert ('Permission denied');
					//	activepopup('Permission denied');
						break;
					case error.UNKNOWN_ERROR:
						//alert ('Unknown error');
					//	activepopup('Unknown error');
						//please use activepopup for messages
						break;
				}
			});
	}
});

function activepopup(t)
{
	$('#information').html(t);
	var len= Number(t.length)*8;
	//alert(len);
	var myWidth = (window.innerWidth/2)-(len/2);
    var myHeight = (window.innerHeight/2);
    
	//var popMargTop
	$('#information').customFadeIn().css({ 'width':len,'left':myWidth});
	
	$("#information").delay(1000).customFadeOut("slow");
	
}
